package cn.rengy.web.framework.wxmp.component.token;

import cn.rengy.tpa.wxmp.exception.WeChatException;
import cn.rengy.tpa.wxmp.token.AccessToken;

/**
 * 授权方接口调用令牌，有效期2小时
 * @author rengy
 *
 */
public class AuthAccessTokenImpl implements AccessToken {
	private String accessToken;
	private ComponentTokenService componentTokenService;
	private String appid;//授权方即公众号appid
	public AuthAccessTokenImpl(ComponentTokenService componentTokenService,String appid){
		this.componentTokenService=componentTokenService;
		this.appid=appid;
	}
	@Override
	public String token() throws WeChatException {
		accessToken=componentTokenService.authAccessToken(appid);
		return accessToken;
	}

	@Override
	public void refresh() throws WeChatException {
		componentTokenService.evictAuthAccessToken(appid, accessToken);
	}

}
